<?php
session_start();
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/database.php');
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/functions.php');
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/class.admin.php');
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/class.forms.php');
//print_r($_POST);
$admin=new admin();
$admin->canView($_SERVER['PHP_SELF']);

$token=$_POST['form_token'];
$form_content=str_replace("</text-area>","</textarea>",$_POST['form_markup']);

file_put_contents($_SERVER['DOCUMENT_ROOT'].'/inc/form_'.$token.'.php',$form_content);
file_put_contents($_SERVER['DOCUMENT_ROOT'].'/inc/logic_'.$token.'.php',$_POST['form_logic']);
$id=$_POST['form_id'];

$criteria=array('form_name'=>$_POST['form_name'],'button_waiting_value'=>$_POST['form_button_waiting_value'],'method'=>$_POST['form_method'],'enctype'=>$_POST['form_enctype'],'inline'=>intval($_POST['form_inline']));//base64_encode();
$admin->saveForm($criteria,$id);
?>
<script>$.fn.message('show','<div class="ok_h_message"><h2>Form updated</h2><p><strong>Form settings have been saved</strong></p></div>');</script>
